using System.Windows;
using System.Windows.Input;
using Microsoft.Practices.Composite.Events;
using Microsoft.Practices.Composite.Presentation.Commands;
using Silverlight.Weblog.Client.DAL.Events;
using Silverlight.Weblog.Client.DAL.ViewModel;
using Silverlight.Weblog.Common.IoC;
using Silverlight.Weblog.Server.DAL;

namespace Silverlight.Weblog.Client.Default.Widgets.ViewModels
{
    public class BlogPostChildCategoriesViewModels : ViewModelBase
    {
        public BlogPostChildCategoriesViewModels(Category model, bool isLast)
        {
            _model = model;
            _isLast = isLast;

            this.RaiseNavigateToCategoryEvent = new DelegateCommand<Category>(c =>
                    IoC.Get<IEventAggregator>().GetEvent<DisplayCategoryEvent>().Publish(c));
        }

        #region Model
        private Category _model;
        public Category Model
        {
            get { return _model; }
            set
            {
                if (_model != value)
                {
                    _model = value;
                    RaisePropertyChanged("Model");
                    RaisePropertyChanged((BlogPostChildCategoriesViewModels vm) => vm.CommaVisiblity);
                }

            }
        }
        #endregion Model


        #region IsLast
        private bool _isLast;
        public bool IsLast
        {
            get { return _isLast; }
            set
            {
                if (_isLast != value)
                {
                    _isLast = value;
                    RaisePropertyChanged("IsLast");
                }

            }
        }
        #endregion IsLast

        #region CommaVisiblity
        public Visibility CommaVisiblity
        {
            get
            {
                if (Model == null)
                    return Visibility.Visible;


                return IsLast 
                    ? Visibility.Collapsed 
                    : Visibility.Visible;
            }
        }
        #endregion CommaVisiblity

        public ICommand RaiseNavigateToCategoryEvent { get; set; }
    }
}